#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    static vector<int> twoSum(vector<int>& price, int target) {
        int left = 0, right = price.size()-1;
        vector<int> ret(2);
        while(left < right)
        {
            //逻辑：
            //当左指针+右指针>目标值，说明最大值大了，所以，right--
            //反之，则说明最小值小了，所以，left++
            if(price[left] + price[right] > target) right--;
            else if(price[left] + price[right] < target) left++;
            else 
            {
                ret[0] = price[left], ret[1] = price[right];
                break;
            }
        }    
        return ret;
    }
};

int main()
{
    // vector<int> price = {3, 9, 12, 15};
    // int target = 18;
    vector<int> price = {8, 21, 27, 34, 52, 66};
    int target = 61;
    auto vc = Solution::twoSum(price, target);
    for(auto i: vc)
    {
        cout << i << " ";
    }
    cout << endl;
    return 0;
}